Cf = {
	version: 1.0
	,prefix: 'cf'
	,emptyFn: function(){}
	,V_HALT: 'cf-cf-cf'
};

/***************************************************************************/
Cf.put = function(/*arguments*/){
	var p, o = arguments[0];
	
	for(var i = 1; i < arguments.length; ++i){
		p = arguments[i];
		for(var j in p) o[j] = p[j];
	}
	
	return o;
};

Cf.putIf = function(/*arguments*/){
	var p, o = arguments[0];
	
	for(var i = 1; i < arguments.length; ++i){
		p = arguments[i];
		for(var j in p){
			if(typeof o[j] !== 'undefined') continue;
			o[j] = p[j];
		}
	}
	
	return o;
};

/***************************************************************************/
Cf.getType = function(o){
	if(null === o || typeof o === 'undefiend') return o;
	return Object.prototype.toString.call(o).match(/\[object (\w+)\]/)[1];
}

Cf.isUndefined = function(o){
	return typeof o === 'undefined';
}

Cf.isDefined = function(o){
	return !Cf.isUndefined(o);
}

Cf.isEmpty = function(o){
	return null === o 
			|| undefined === o 
			|| '' === o
			|| (function(){
					for(var i in o){
						if(o.hasOwnProperty(i)) return false;
					}
					return true;
				})();
}

Cf.isString = function(o){
	return typeof o === 'string';	
}

Cf.isNumber = function(o){
	return typeof o === 'number';	
}

Cf.isInt = function(o, unsigned){
	var int = parseInt(o);
	return unsigned? int === o && o >= 0 : int === o;	
}


Cf.isFloat = function(o, unsigned){
	var float = parseFloat(o);
	return unsigned? float === o && o >= 0 : float === o;
}

Cf.isArray = function(o){
	return 'Array' == Cf.getType(o);
}

Cf.isObject = function(o){
	return 'Object' == Cf.getType(o);
}

Cf.isDate = function(o){
	return 'Date' == Cf.getType(o);
}

Cf.isRegExp = function(o){
	return 'RegExp' == Cf.getType(o);
}

Cf.isFunction = function(o){
	return 'Function' == Cf.getType(o);
}

Cf.isDom = function(o){
	return /HTML(\w*)Element/.test(Cf.getType(o));
}

/***************************************************************************/
Cf.put(Cf, (function(){
	var ua = navigator.userAgent.toLowerCase();
	
	return {
		isFF: /firefox/.test(ua)
		,isChrome: /chrome/.test(ua)
		,isOpera: /opera/.test(ua)
		,isIE: /msie/.test(ua)
		,isLinux: /linux/.test(ua)
		,isWindow: /windows|win32/.test(ua)
		,isMac: /macintosh|mac os x/.test(ua)
		,isHttps: /https/.test(window.location.protocol)
	};
	
})());

Cf.seq = function(){
	var i = 0;
	return function(){
		i ++;
		return i;
	};
}();

Cf.ns = function(/** arguments **/){
	for(var i = 0; i < arguments.length; ++i){
		var o = window
			,n = arguments[i]
			,parts = n.split('.');
			
		for(var j = 0; j < parts.length; ++j){
			o = o[parts[j]] = o[parts[j]] || {};
		}
	}
};

Cf.each = function(o, fn, scope){
	if(Cf.isArray(o)){
		for(var i = 0, len = o.length; i < len; ++i){
			if(Cf.V_HALT === fn.call(scope || fn, o[i], i, o))return Cf.V_HALT;
		}
	}	
};

Cf.getDom = function(o){
	if(Cf.isDom(o)) return o;
	if(o instanceof Cf.dom.Element) return o.getDom();
	if(Cf.isString(o)) return document.querySelector(o);
	return Cf.dom.Helper.create(o);	
};

Cf.getEl = (function(){
	var caches = [];
	
	return function(el){
		if(el && el.id && caches[el.id]){
			return caches[el.id];
		}
		
		el = new Cf.dom.Element(el);
		caches[el.id] = el;
		return el;
	};
})();

Cf.createFn = function(o){
	var fn = o.fn;
	delete o.fn;
	return fn.create(o);
};

Cf.equals = function(o1, o2){
	if(!o1 && !o2) return true;
	if(!o1 || !o2) return false;
	
  for(var i in o1){
	if(o1[i] !== o2[i]) return false;
  }
  
  for(var i in o2) {
	if(o1[i] !== o2[i]) return false;
  }
  return true;
};

Cf.ready = (function(){
	var isReady = false;
		cb = [];
	
	function onLoad(){
		isReady = true;
		
		for(var i = 0, len = cb.length; i < len; ++i){
			cb[i]();
		}
	};
	
	if(Cf.isIE){
		document.onreadystatechange = function(){
			if(document.readyState == 'complete') onLoad();
		};
	}else{
		document.addEventListener('DOMContentLoaded', onLoad, false);
	}
	
	return function(fn, scope){
		var f = scope? fn.bind(scope) : fn;
		isReady? f() : cb.push(f);
		return isReady;
	};
})();

Cf.ns('Cf.dom', 'Cf.util');